package com.eden.manage.controller;

import com.eden.manage.dto.PageComDto;
import com.eden.manage.dto.user.UserDto;
import com.eden.manage.req.query.UserQuery;
import com.eden.manage.service.UserService;
import eden.api.common.model.EdenPageResult;
import eden.api.common.model.EdenResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RequestMapping("user")
@RestController
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @PostMapping("index")
    public EdenPageResult<?> pageList(@RequestBody UserQuery query){
        PageComDto<UserDto> pageDto = userService.pageList(query);
        return EdenPageResult.ok(pageDto.getList(), pageDto.getCount());
    }


    @PostMapping("")
    public EdenResult<?> edit(@RequestBody @Valid UserDto userDto){
        userService.editUser(userDto);
        return EdenResult.ok("");
    }

    @DeleteMapping("{userAccount}")
    public EdenResult<?> delete(@PathVariable("userAccount") String userAccount){
        userService.deleteUser(userAccount);
        return EdenResult.ok("");
    }
    @GetMapping("current/detail")
    public EdenResult<?> currentDetail(){
        return EdenResult.ok(userService.getUserFrontInfo());
    }

}
